<template>
    <div class="project-edit contain-edit">
        <div class="header">
           <p>优惠规则>>设置优惠</p>
        </div>
       <div class="main">
           <el-form :model="information" :rules="rules" ref="information" label-width="120px" class="">
                <el-form-item label="优惠规则" prop="discount">
                    租金的<el-input
                        type="text"
                        style="width:100px;margin:0 20px"
                        placeholder="输入数字"
                        v-model.number="information.discount">
                    </el-input>折
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('information')"  :loading="loading">保存</el-button>
                </el-form-item>
           </el-form>
       </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js');
let common = require("../../common.js");
  export default {
    data() {
        return {
            information:{
                discount:''
            },
            rules: {
                discount: [
                    { required: true, message: '请输入折扣', trigger: 'blur' },
                    { type: 'number', message: '折扣必须为数字值'}
                ],
            },
            loading: false,
            identify:''
        };
    },
    components:{
      
    },
    watch:{
    },
    mounted() {
        this.identify = sessionStorage.getItem("identify");
        this.getDetail(); 
    },
    methods: {
        getDetail(){
            let url;
            if (this.identify == 1) {
                url =  CONSTANT.URL.SYSVAR.FINDYEARRENT
            } else {
                url =  CONSTANT.URL.L_SYSVAR.FINDYEARRENT
            }
           let data = {} ;
           common.requestAjax(url,JSON.stringify(data),null,(res)=>{
               this.information.discount = res.data.bussData
           }) 
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.loading = true;
                 let url;
                if (this.identify == 1) {
                    url =  CONSTANT.URL.SYSVAR.SETYEARRENT
                } else {
                    url =  CONSTANT.URL.L_SYSVAR.SETYEARRENT
                }
                common.requestAjax(url, {}, this.information, res => {
                    if(res.status == 200) {
                        this.$message({
                            type: 'success',
                            message: '保存成功!'
                        });
                        this.loading = false;
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.msg
                        });
                        this.loading = false;
                    }
                });
            } else {
                console.log('error submit!!');
                return false;
            }
            });
        },
    }
  }
</script>

<style lang="scss" >
    .el-form-item__content{
        margin-left: 0;
    }
    .project-edit{
        .el-form-item__label{
            font-size: 13px!important;
        }
        .el-range-separator{
            width: 10%!important;;
        }
        .file-load .el-upload-list__item{
            width:50%!important;
        }
    }
</style>